package output

import (
	"errors"
	"github.com/gin-gonic/gin"
	"net/http"
)

var (
	ErrNoParam  = errors.New("参数错误")
	ErrNoRecord = errors.New("未找到数据")
)

var (
	ErrNoParamCode  int64 = 406
	ErrNoRecordCode int64 = 501
)

func NewOutput() *output {
	return &output{}
}

type output struct {
}

// Success 定义输出错误码及格式
func (o *output) Success(ctx *gin.Context, data interface{}) {
	ctx.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "success",
		"data": data,
	})
	return
}

// Failure 定义输出错误码及格式
func (o *output) Failure(ctx *gin.Context, code int, msg string) {
	ctx.JSON(http.StatusInternalServerError, gin.H{
		"code": code,
		"msg":  msg,
	})
	return
}
